home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / hash.s < prev    next >
Text File  |  1999-02-04  |  6KB  |  360 lines

  1.  
  2. ; Storm C Compiler
  3. ; Work2:Mesa3/Mesa-3.0/src/hash.c
  4.     mc68030
  5.     mc68881
  6.     XREF    _printf
  7.     XREF    _free
  8.     XREF    _calloc
  9.     XREF    _std__in
  10.     XREF    _std__out
  11.     XREF    _std__err
  12.  
  13.     SECTION "_NewHashTable:0",CODE
  14.  
  15.  
  16. ;struct HashTable *NewHashTable(void)
  17.     XDEF    _NewHashTable
  18. _NewHashTable
  19. L35
  20.     pea    1.w
  21.     pea    $FA8.w
  22.     jsr    _calloc
  23.     addq.w    #$8,a7
  24.     rts
  25.  
  26.     SECTION "_DeleteHashTable:0",CODE
  27.  
  28.     rts
  29.  
  30. ;void DeleteHashTable(struct HashTable *table)
  31.     XDEF    _DeleteHashTable
  32. _DeleteHashTable
  33.     movem.l    d2/a2/a3,-(a7)
  34.     move.l    $10(a7),a3
  35. L36
  36. ;   for (i=0;
  37.     moveq    #0,d2
  38.     bra.b    L41
  39. L37
  40. ;      struct HashEntry *entry = table->Table[i];
  41.     move.l    0(a3,d2.l*4),a0
  42. ;      while (entry) 
  43.     bra.b    L39
  44. L38
  45. ;     struct HashEntry *next = entry->Next;
  46.     move.l    $8(a0),a2
  47. ;     free(entry);
  48.     move.l    a0,-(a7)
  49.     jsr    _free
  50.     addq.w    #4,a7
  51. ;     entry = next;
  52.     move.l    a2,a0
  53. L39
  54.     cmp.w    #0,a0
  55.     bne.b    L38
  56. L40
  57.     addq.l    #1,d2
  58. L41
  59.     cmp.l    #$3E9,d2
  60.     blo.b    L37
  61. L42
  62. ;   free(table);
  63.     move.l    a3,-(a7)
  64.     jsr    _free
  65.     addq.w    #4,a7
  66.     movem.l    (a7)+,d2/a2/a3
  67.     rts
  68.  
  69.     SECTION "_HashLookup:0",CODE
  70.  
  71.  
  72. ;void *HashLookup(const struct HashTable *table, GLuint key)
  73.     XDEF    _HashLookup
  74. _HashLookup
  75.     move.l    d2,-(a7)
  76.     move.l    $C(a7),d1
  77.     move.l    $8(a7),a0
  78. L43
  79. ;   pos = key % TABLE_SIZE;
  80.     move.l    d1,d0
  81.     divul.l    #$3E9,d2:d0
  82. ;   entry = table->Table[pos];
  83.     move.l    d2,d0
  84.     move.l    0(a0,d0.l*4),a0
  85. ;   while (entry) 
  86.     bra.b    L47
  87. L44
  88. ;      if (entry->Key == key) 
  89.     move.l    (a0),d0
  90.     cmp.l    d1,d0
  91.     bne.b    L46
  92. L45
  93.     move.l    4(a0),d0
  94.     move.l    (a7)+,d2
  95.     rts
  96. L46
  97. ;      entry = entry->Next;
  98.     move.l    $8(a0),a0
  99. L47
  100.     cmp.w    #0,a0
  101.     bne.b    L44
  102. L48
  103.     moveq    #0,d0
  104.     move.l    (a7)+,d2
  105.     rts
  106.  
  107.     SECTION "_HashInsert:0",CODE
  108.  
  109.  
  110. ;void HashInsert(struct HashTable *table, GLuint key, void *data)
  111.     XDEF    _HashInsert
  112. _HashInsert
  113.     movem.l    d2/d3/a2/a3,-(a7)
  114.     movem.l    $18(a7),d2/a2
  115.     move.l    $14(a7),a3
  116. L49
  117. ;   if (key > table->MaxKey)
  118.     move.l    a3,a0
  119.     cmp.l    $FA4(a0),d2
  120.     bls.b    L51
  121. L50
  122. ;      table->MaxKey = key;
  123.     move.l    a3,a0
  124.     move.l    d2,$FA4(a0)
  125. L51
  126. ;   pos = key % TABLE_SIZE;
  127.     move.l    d2,d3
  128.     divul.l    #$3E9,d0:d3
  129.     move.l    d0,d3
  130. ;   entry = table->Table[pos];
  131.     move.l    0(a3,d3.l*4),a0
  132. ;   while (entry) 
  133.     bra.b    L55
  134. L52
  135. ;      if (entry->Key == key) 
  136.     move.l    (a0),d0
  137.     cmp.l    d2,d0
  138.     bne.b    L54
  139. L53
  140. ;     entry->Data = data;
  141.     move.l    a2,4(a0)
  142.     movem.l    (a7)+,d2/d3/a2/a3
  143.     rts
  144. L54
  145. ;      entry = entry->Next;
  146.     move.l    $8(a0),a0
  147. L55
  148.     cmp.w    #0,a0
  149.     bne.b    L52
  150. L56
  151. ;   entry = (struct HashEntry *) calloc(sizeof(struct HashEntry), 
  152.     pea    1.w
  153.     pea    $C.w
  154.     jsr    _calloc
  155.     addq.w    #$8,a7
  156.     move.l    d0,a0
  157. ;   entry->Key = key;
  158.     move.l    d2,(a0)
  159. ;   entry->Data = data;
  160.     move.l    a2,4(a0)
  161. ;   entry->Next = table->Table[pos];
  162.     move.l    0(a3,d3.l*4),$8(a0)
  163. ;   table->Table[pos] = entry;
  164.     move.l    a0,0(a3,d3.l*4)
  165.     movem.l    (a7)+,d2/d3/a2/a3
  166.     rts
  167.  
  168.     SECTION "_HashRemove:0",CODE
  169.  
  170.  
  171. ;void HashRemove(struct HashTable *table, GLuint key)
  172.     XDEF    _HashRemove
  173. _HashRemove
  174.     movem.l    d2/a2/a3,-(a7)
  175.     move.l    $14(a7),d2
  176.     move.l    $10(a7),a3
  177. L57
  178. ;   pos = key % TABLE_SIZE;
  179.     move.l    d2,d1
  180.     divul.l    #$3E9,d0:d1
  181.     move.l    d0,d1
  182. ;   prev = NULL;
  183.     sub.l    a1,a1
  184. ;   entry = table->Table[pos];
  185.     move.l    0(a3,d1.l*4),a0
  186. ;   while (entry) 
  187.     bra.b    L64
  188. L58
  189. ;      if (entry->Key == key) 
  190.     move.l    (a0),d0
  191.     cmp.l    d2,d0
  192.     bne.b    L63
  193. L59
  194. ;         if (prev) 
  195.     cmp.w    #0,a1
  196.     beq.b    L61
  197. L60
  198. ;            prev->Next = entry->Next;
  199.     move.l    $8(a0),$8(a1)
  200.     bra.b    L62
  201. L61
  202. ;            table->Table[pos] = entry->Next;
  203.     move.l    $8(a0),0(a3,d1.l*4)
  204. L62
  205. ;         free(entry);
  206.     move.l    a0,-(a7)
  207.     jsr    _free
  208.     addq.w    #4,a7
  209.     movem.l    (a7)+,d2/a2/a3
  210.     rts
  211. L63
  212. ;      prev = entry;
  213.     move.l    a0,a1
  214. ;      entry = entry->Next;
  215.     move.l    $8(a0),a0
  216. L64
  217.     cmp.w    #0,a0
  218.     bne.b    L58
  219. L65
  220.     movem.l    (a7)+,d2/a2/a3
  221.     rts
  222.  
  223.     SECTION "_HashFirstEntry:0",CODE
  224.  
  225.  
  226. ;GLuint HashFirstEntry(const struct HashTable *table)
  227.     XDEF    _HashFirstEntry
  228. _HashFirstEntry
  229.     move.l    4(a7),a1
  230. L66
  231. ;   for (pos=0;
  232.     moveq    #0,d0
  233.     bra.b    L70
  234. L67
  235. ;      if (table->Table[pos])
  236.     tst.l    0(a1,d0.l*4)
  237.     beq.b    L69
  238. L68
  239.     move.l    0(a1,d0.l*4),a0
  240.     move.l    (a0),d0
  241.     rts
  242. L69
  243.     addq.l    #1,d0
  244. L70
  245.     cmp.l    #$3E9,d0
  246.     blo.b    L67
  247. L71
  248. ;         return 
  249.     moveq    #0,d0
  250.     rts
  251.  
  252.     SECTION "_HashPrint:0",CODE
  253.  
  254.  
  255. ;void HashPrint(const struct HashTable *table)
  256.     XDEF    _HashPrint
  257. _HashPrint
  258.     movem.l    d2/a2/a3,-(a7)
  259.     move.l    $10(a7),a3
  260. L73
  261. ;   for (i=0;
  262.     moveq    #0,d2
  263.     bra.b    L78
  264. L74
  265. ;      struct HashEntry *entry = table->Table[i];
  266.     move.l    0(a3,d2.l*4),a2
  267. ;      while (entry) 
  268.     bra.b    L76
  269. L75
  270. ;     printf("%u %p\n", entry->Key, entry->Data);
  271.     move.l    4(a2),-(a7)
  272.     move.l    (a2),-(a7)
  273.     move.l    #L72,-(a7)
  274.     jsr    _printf
  275.     add.w    #$C,a7
  276. ;     entry = entry->Next;
  277.     move.l    $8(a2),a2
  278. L76
  279.     cmp.w    #0,a2
  280.     bne.b    L75
  281. L77
  282.     addq.l    #1,d2
  283. L78
  284.     cmp.l    #$3E9,d2
  285.     blo.b    L74
  286. L79
  287.     movem.l    (a7)+,d2/a2/a3
  288.     rts
  289.  
  290. L72
  291.     dc.b    '%u %p',$A,0
  292.  
  293.     SECTION "_HashFindFreeKeyBlock:0",CODE
  294.  
  295.  
  296. ;GLuint HashFindFreeKeyBlock(const struct HashTable *table, GLuint nu
  297.     XDEF    _HashFindFreeKeyBlock
  298. _HashFindFreeKeyBlock
  299.     movem.l    d2-d6/a2,-(a7)
  300.     move.l    $20(a7),d6
  301.     move.l    $1C(a7),a2
  302. L80
  303. ;   GLuint maxKey = ~((GLuint) 0);
  304.     moveq    #-1,d5
  305. ;   if (maxKey - numKeys > table->MaxKey) 
  306.     move.l    d5,d1
  307.     sub.l    d6,d1
  308.     cmp.l    $FA4(a2),d1
  309.     bls.b    L82
  310. L81
  311.     move.l    $FA4(a2),d0
  312.     addq.l    #1,d0
  313.     movem.l    (a7)+,d2-d6/a2
  314.     rts
  315. L82
  316. ;      GLuint freeCount = 0;
  317.     moveq    #0,d3
  318. ;      GLuint freeStart = 0;
  319.     moveq    #0,d4
  320. ;      for (key=0;
  321.     moveq    #0,d2
  322.     bra.b    L88
  323. L83
  324. ;     if (HashLookup(table, key)) 
  325.     move.l    d2,-(a7)
  326.     move.l    a2,-(a7)
  327.     jsr    _HashLookup
  328.     addq.w    #$8,a7
  329.     tst.l    d0
  330.     beq.b    L85
  331. L84
  332. ;        freeCount = 0;
  333.     moveq    #0,d3
  334. ;        freeStart = key+1;
  335.     move.l    d2,d4
  336.     addq.l    #1,d4
  337.     bra.b    L87
  338. L85
  339. ;        freeCount++;
  340.     addq.l    #1,d3
  341. ;        if (freeCount == numKeys) 
  342.     cmp.l    d6,d3
  343.     bne.b    L87
  344. L86
  345.     move.l    d4,d0
  346.     movem.l    (a7)+,d2-d6/a2
  347.     rts
  348. L87
  349.     addq.l    #1,d2
  350. L88
  351.     cmp.l    d5,d2
  352.     bne.b    L83
  353. L89
  354. ;           return 
  355.     moveq    #0,d0
  356.     movem.l    (a7)+,d2-d6/a2
  357.     rts
  358.  
  359.     END
  360.